import { playerState } from '../../script/game/GameDef';
import { GameManager } from '../../script/game/GameManager';
import { UIConfigData } from '../config/GameUIConfig';
import { LayerPopUp } from './LayerPopUp';
import { LayerUI } from './LayerUI';
const { ccclass, property } = cc._decorator;

export enum LayerType {
    Game = "LayerGame",
    UI = "LayerUI",
    LayerPopUp = "LayerPopUp"
}

export interface UIConfig {
    layer: string; 
    prefab: string;    
}

export class UIManager {
    root: cc.Node;
    private ui: LayerUI;
    private popup: LayerPopUp;

    openView(layerID: number) {
        let config = UIConfigData[layerID];
        if (config == null) {
            cc.warn("打开失败，配置信息不存在");
            return;
        }
        switch (config.layer) {
            case LayerType.UI:
                this.ui.add(config);
                break;
            case LayerType.LayerPopUp:
                this.popup.add(config);
                break;
        }
    }

    removeView(layerID: number) {
        let config = UIConfigData[layerID];
        if (config == null) {
            cc.warn("删除失败，配置信息不存在");
            return;
        }
        switch (config.layer) {
            case LayerType.LayerPopUp:
                this.popup.remove(config.prefab);
            case LayerType.UI:
                this.ui.remove(config.prefab);
                break;
        }
    }

    constructor(root: cc.Node) {
        this.root = root;

        this.popup = new LayerPopUp(LayerType.LayerPopUp);
        this.ui = new LayerUI(LayerType.UI);
        // this.popup.anchorY = 1;
        // this.ui.anchorY = 1;
        root.addChild(this.ui);
        root.addChild(this.popup);
    }
}


